package com.hzit.hzb.core.controller.admin;


import com.hzit.common.result.R;
import com.hzit.hzb.core.pojo.entity.Lend;
import com.hzit.hzb.core.pojo.entity.LendItem;
import com.hzit.hzb.core.service.LendItemService;
import com.hzit.hzb.core.service.LendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigurationPackage;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 标的准备表 前端控制器
 * </p>
 *
 * @author hbxfwf
 * @since 2024-08-27
 */
@RestController
@RequestMapping("/admin/core/lend")
public class AdminLendController {

	@Autowired
	private LendService lendService;
	@Autowired
	private LendItemService lendItemService;
	@GetMapping("/list")
	public R list(){
		List<Lend> list = lendService.selectList();
		return R.ok().data("list",list);
	}

	/**
	 * 根据标的id展示标的与借款人评情
	 * @param id
	 * @return
	 */
	@GetMapping("/show/{id}")
	public R show(@PathVariable("id") Long id){
		Map<String,Object> resultMap = lendService.show(id);
		return R.ok().data("lendDetail",resultMap);
	}

	/**
	 * 放款
	 * @param id
	 * @return
	 */
	@GetMapping("/makeLoan/{id}")
	public R makeLoan(@PathVariable("id") Long id){
		lendService.makloan(id);

		return R.ok().message("放款成功");
	}

	/**
	 * 根据标的id查询标的项列表
	 * @param id
	 * @return
	 */
	@GetMapping("/fetchLendItemList/{id}")
	public R fetchLendItemList(@PathVariable("id") Long id){
		List<LendItem> lendItems = lendItemService.fetchLendItemList(id);
		return R.ok().data("list",lendItems);
	}
}

